using System;
using System.Collections.Generic;

using System.Windows.Forms;

using Mono.GetOptions;


namespace FieldStat
{
    public class MonoCovOptions : Options
    {
        //[Option("No progress messages during the export process", "no-progress")]
        //public bool quiet = false;

        [Option("Do not perform coderank analysis.", "no-coderank")]
        public bool nocodeRank = false;

        [Option("Path of Generated Reports (default \"output\").", "output-dir")]
        public string outputDirectory = "output";

        [Option("Path of Application Repository to collect data over.", "app-repos")]
        public string applicationRepository="";

        [Option("Include only specified patterns: (e.g. \"System.IO.*;System.Data.*;\").", "patterns")]
        public string filters="";

        [Option("Path of Coverage XML Files generated by monocov (default \"Data/Coverage\").", "coverage-path")]
        public string coveragePath = "../Data";

        public override WhatToDoNext DoAbout()
        {
            base.DoAbout();
            return WhatToDoNext.AbandonProgram;
        }
    }

    static class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            DataCollection.Plugins.InitPlugins();

            //RunConsole(args);
            
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());

        }

        //FieldStat --coverage-path="../../../Data/Coverage Data/coverage_output" FieldStat.exe
        static void RunConsole(string[] args)
        {
            MonoCovOptions options = new MonoCovOptions();
            options.ProcessArgs(args);

            // List of assemblies/executables or a directory containing executables.
            args = options.RemainingArguments;

            if (args.Length == 0 && options.applicationRepository == "")
            {
                options.DoHelp();
            }
            Console.WriteLine("app-repos: "+ options.applicationRepository);
            Console.WriteLine("coveragePath: " + options.coveragePath);
            Console.WriteLine("filters: " + options.filters);
            Console.WriteLine("no-coderank: " + options.nocodeRank);
            Console.WriteLine("outputDir: " + options.outputDirectory);
            Console.WriteLine("args: " + string.Join(",", options.RemainingArguments));

            ParameterData data = new ParameterData();
            ExportData export = new ExportData(data.Results, options.outputDirectory);

            if( options.applicationRepository != "" )
                data.LoadApplicationRepository( options.applicationRepository );
            else
                data.LoadAssemblies( args );
            
            if( options.filters != "" )
                data.LoadFilters( options.filters.Split(';') );
            
            data.LoadCoverage( options.coveragePath );
            
            data.ComputeResults();
            export.ExportResults();
        }
    }
}